home *** CD-ROM | disk | FTP | other *** search
/ The Best of Down Under Games / The Best of Down Under Games.iso / 3dfx Screen Savers / Motion Blurring / SAVER13.C next >
C/C++ Source or Header  |  1997-07-28  |  6KB  |  237 lines

  1. /**********************************************************
  2.  
  3.         3DFX Screensaver Competition Entry #13
  4.             by Paul Steffen
  5.             <psteffen@concentric.net>
  6.             <http://steffen.home.ml.org>
  7.  
  8.         Here's the source to my tiny starplane[?]
  9.         saver.  No serious attempt at optimizing
  10.         was attempted as the CPU does very little
  11.         work, anyway.
  12.  
  13.         I dedicate this screensaver to Jeff
  14.         Minter, who should rewrite Trip-O- Tron
  15.         for 3DFX!
  16.  
  17. ***********************************************************/
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <glide.h>
  23.  
  24. static char mapfile[]="starmap.3df";
  25. static float n=3.141592654/100;
  26.  
  27. GrMipMapId_t maphandle;
  28. Gu3dfInfo TexInfo;
  29. GrHwConfiguration hw;
  30. GrVertex point1,point2,point3;
  31. FxU32 framebuffer,TextureMemStart,TextureMemEnd;
  32.  
  33. float v[4],r[8],cn,f[2]={0,0.05};
  34. int c,fade_in,error;
  35.  
  36.  
  37. void
  38. initGlide()
  39. {
  40.    grGlideInit();
  41.    if (grSstQueryHardware(&hw))
  42.    {
  43.        grSstSelect(0);
  44.        grSstWinOpen( 0,
  45.                      GR_RESOLUTION_640x480,
  46.                      GR_REFRESH_60Hz,
  47.                      GR_COLORFORMAT_ABGR,
  48.                      GR_ORIGIN_UPPER_LEFT,
  49.                      GR_SMOOTHING_ENABLE,
  50.                      2);
  51.    } else {
  52.        printf("Cannot initialize Voodoo chipset.\n");
  53.        error++;
  54.    }
  55.  
  56.     grRenderBuffer(GR_BUFFER_BACKBUFFER);
  57.     grDepthBufferMode(GR_DEPTHBUFFER_DISABLE);
  58.  
  59. // setup up color combine modes
  60.  
  61.     grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
  62.                     GR_COMBINE_FACTOR_NONE,
  63.                     GR_COMBINE_LOCAL_ITERATED,
  64.                     GR_COMBINE_OTHER_NONE,
  65.                     FXFALSE);
  66.  
  67.     guColorCombineFunction(GR_COLORCOMBINE_DECAL_TEXTURE);  //  oh well...
  68.     grTexCombineFunction(GR_TMU0, GR_TEXTURECOMBINE_DECAL); //  fix this l8r.
  69.  
  70.     grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
  71.                    GR_COMBINE_FACTOR_ONE,
  72.                    GR_COMBINE_LOCAL_NONE,
  73.                    GR_COMBINE_OTHER_CONSTANT,
  74.                    FXFALSE);
  75.  
  76.     grAlphaBlendFunction( GR_BLEND_SRC_ALPHA,
  77.                           GR_BLEND_ONE_MINUS_SRC_ALPHA,
  78.                           GR_BLEND_ONE,
  79.                           GR_BLEND_ZERO);
  80.  
  81.     grAlphaTestFunction(GR_CMP_ALWAYS);
  82.     guAlphaSource(GR_ALPHASOURCE_ITERATED_ALPHA);
  83.  
  84.  
  85.  
  86.     if(!gu3dfGetInfo(mapfile, &TexInfo))
  87.     {
  88.         printf("Could not find %s image.\n",mapfile);
  89.         grGlideShutdown();
  90.         exit(-1);
  91.     }
  92.         TexInfo.data = malloc(TexInfo.mem_required);
  93.         if(TexInfo.data==0)
  94.         {
  95.             printf("Not enough memory to load %s.\n", mapfile);
  96.             grGlideShutdown();
  97.             exit(-1);
  98.         }
  99.         gu3dfLoad(mapfile, &TexInfo);
  100.  
  101.         maphandle = guTexAllocateMemory(0, GR_MIPMAPLEVELMASK_BOTH,
  102.                                     TexInfo.header.width,
  103.                                     TexInfo.header.height,
  104.                                     TexInfo.header.format,
  105.                                     GR_MIPMAP_NEAREST_DITHER,
  106.                                     TexInfo.header.small_lod,
  107.                                     TexInfo.header.large_lod,
  108.                                     TexInfo.header.aspect_ratio,
  109.                                     GR_TEXTURECLAMP_WRAP,
  110.                                     GR_TEXTURECLAMP_WRAP,
  111.                                     GR_TEXTUREFILTER_BILINEAR,
  112.                                     GR_TEXTUREFILTER_BILINEAR,
  113.                                     0.f,
  114.                                     FXFALSE);
  115.  
  116.     guTexDownloadMipMap(maphandle, TexInfo.data, &TexInfo.table.nccTable);
  117. };
  118.  
  119. void
  120. draw(float size, float x, float y, float rot, float alpha)
  121. {
  122.  
  123.     float minpoint,maxpoint,st,ct;
  124.     float stminx,stmaxx;
  125.     float ctminx,ctmaxx;
  126.     float stminy,stmaxy;
  127.     float ctminy,ctmaxy;
  128.  
  129.     size *= sqrt(size);
  130.     st=sin(rot);
  131.     ct=cos(rot);
  132.     minpoint=128-size;
  133.     maxpoint=128+size;
  134.  
  135.     point1.a=alpha;
  136.     point2.a=alpha;
  137.     point3.a=alpha;
  138.  
  139.     point1.x=0; point1.y=0;
  140.     point2.x=640; point2.y=0;
  141.     point3.x=0; point3.y=480;
  142.  
  143.     r[0]=st*(maxpoint+x);
  144.     r[1]=st*(maxpoint+y);
  145.     r[2]=st*(minpoint+x);
  146.     r[3]=st*(minpoint+y);
  147.     r[4]=ct*(maxpoint+x);
  148.     r[5]=ct*(maxpoint+y);
  149.     r[6]=ct*(minpoint+x);
  150.     r[7]=ct*(minpoint+y);
  151.  
  152.     point1.oow=1.0;
  153.     point1.tmuvtx[0].sow=r[6]-r[3];
  154.     point1.tmuvtx[0].tow=r[2]+r[7];
  155.  
  156.     point2.oow=1.0;
  157.     point2.tmuvtx[0].sow=r[4]-r[3];
  158.     point2.tmuvtx[0].tow=r[0]+r[7];
  159.  
  160.     point3.oow=1.0;
  161.     point3.tmuvtx[0].sow=r[6]-r[1];
  162.     point3.tmuvtx[0].tow=r[2]+r[5];
  163.  
  164.     grDrawTriangle(&point1,&point2,&point3);
  165.  
  166.     point1.x=640; point1.y=0;
  167.     point2.x=640; point2.y=480;
  168.     point3.x=0; point3.y=480;
  169.  
  170.     point1.oow=1.0;
  171.     point1.tmuvtx[0].sow=r[4]-r[3];
  172.     point1.tmuvtx[0].tow=r[0]+r[7];
  173.  
  174.     point2.oow=1.0;
  175.     point2.tmuvtx[0].sow=r[4]-r[1];
  176.     point2.tmuvtx[0].tow=r[0]+r[5];
  177.  
  178.     point3.oow=1.0;
  179.     point3.tmuvtx[0].sow=r[6]-r[1];
  180.     point3.tmuvtx[0].tow=r[2]+r[5];
  181.  
  182.     grDrawTriangle(&point1,&point2,&point3);
  183. }
  184.  
  185. void
  186. update()
  187. {
  188.     c--;
  189.  
  190.     cn=c*n;
  191.  
  192.     v[0] = 50+(sin(cn*.3)*cos(cn*.5))*100;
  193.     v[1] = c+(sin(cn*.7)*cos(cn*.6))*512;
  194.     v[2] = c+(cos(cn*.3)*sin(cn))*512;
  195.     v[3] = sin(cn*.5)+cos(cn*.6);
  196.  
  197.     if(fade_in)
  198.     {
  199.         f[0] += f[1];
  200.         if (f[0]>1.0)
  201.         {
  202.             f[0]=1.0;
  203.             fade_in=-1;
  204.         }
  205.     }
  206.  
  207.  
  208.  
  209.     guTexSource(maphandle);
  210.     draw( v[0]+50, v[1]*.50, v[2]*.50, v[3],  100*f[0]  );
  211.     draw( v[0]+25, v[1]*.25, v[2]*.25, v[3],  60*f[0]   );
  212.     draw( v[0],    v[1],     v[2],     v[3],  40*f[0]   );
  213.     grBufferSwap(2);
  214. }
  215.  
  216.  
  217. int
  218. main(int argc, char *argv[])
  219. {
  220.     printf("3DFX Screensaver Competition Entry #13\n");
  221.     printf("written by Paul G. Steffen\n");
  222.     printf("<psteffen@concentric.net>\n");
  223.  
  224.     initGlide();
  225.     if (!error)
  226.         exit;
  227.     fade_in=1;
  228.     while(!kbhit())
  229.     {
  230.         update();
  231.     }
  232.     getchar();
  233.     grGlideShutdown();
  234. }
  235.  
  236.  
  237.